using System;
using System.Collections.Generic;
using System.Linq;

namespace Voodoo.Sauce.Internal.Extension
{
	public static class ListExtension
	{
		public static bool SequenceEqualsIgnoreOrder<T>(this List<T> list1, List<T> list2, Func<T, object> orderBy)
		{
			if (list1 == null && list2 == null)
			{
				return true;
			}
			if (list1 == null || list2 == null)
			{
				return false;
			}
			if (list1.Count != list2.Count)
			{
				return false;
			}
			if (list1.Count == 0 && list2.Count == 0)
			{
				return true;
			}
			List<T> first = list1.OrderBy(orderBy).ToList();
			List<T> second = list2.OrderBy(orderBy).ToList();
			return first.SequenceEqual(second);
		}
	}
}
